package cn.dcw.pethome.system.service.impl;

import cn.dcw.pethome.basic.service.impl.BaseServiceImpl;
import cn.dcw.pethome.system.domain.DictionaryDetail;
import cn.dcw.pethome.system.mapper.DictionaryDetailMapper;
import cn.dcw.pethome.system.service.IDictionaryTypeService;
import cn.dcw.pethome.system.domain.DictionaryType;
import cn.dcw.pethome.system.mapper.DictionaryTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/*
部门管理
 */
@Service

public class DictionaryTypeServiceImpl extends BaseServiceImpl<DictionaryType> implements IDictionaryTypeService {
    //加载部门mapper
    @Autowired
    private DictionaryTypeMapper mapper;
    @Autowired
    private DictionaryDetailMapper detailMapper;

    //添加部门
    @Override
    @Transactional
    public void add(DictionaryType dictionaryType) {
        mapper.add(dictionaryType);
       this.update(dictionaryType);
    }


  @Override
    @Transactional
    public void update(DictionaryType dictionaryType) {
        mapper.update(dictionaryType);
    }

    @Override
    @Transactional
    public void delete(Long id) {

        //通过id查询到关联的数据
        DictionaryDetail detail = detailMapper.findOneByTypesId(id);
        if(detail!=null){
            detailMapper.delete(detail.getId());//删除关联数据
        }
        mapper.delete(id);
    }

    /**
     * 二级联动
     * @return
     */
  /*  @Override
    public List<DictionaryType> getTree() {
        return mapper.getTree();
    }*/
}
